﻿using Net_SCADA;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WZXC_GBL_QUERY
{
    public class PubPrint
    {

        public static string LoadPrinters(PrintDocument print, ComboBox cmb_Printers)
        {
            string sDefault = "";
            if (PrinterSettings.InstalledPrinters.Count == 0) return sDefault;
            Ini setting = new Ini(Application.StartupPath + @"\settings\Setting.dat");
            sDefault = setting.ReadValue("Printer", "Default");

            foreach (string sPrint in PrinterSettings.InstalledPrinters)//获取所有打印机名称
            {
                cmb_Printers.Items.Add(sPrint);
            }
            if (!cmb_Printers.Items.Contains(sDefault))
            {
                sDefault = print.PrinterSettings.PrinterName;//默认打印机名
                setting.Write("Printer", "Default", sDefault);
            }
            print.PrinterSettings.PrinterName = cmb_Printers.Text = sDefault;//显示默认驱动名称

            return sDefault;
        }

        public static void SaveDefaultPrinter(string printername)
        {

            Ini setting = new Ini(Application.StartupPath + @"\settings\Setting.dat");
            setting.Write("Printer", "Default", printername);
        }

        //private void PrintTitle(Graphics g, string title, int lcr)
        //{
        //    Font ft = new Font("微软雅黑", 16f, FontStyle.Regular);
        //    Brush brush = new SolidBrush(Color.Black);//画刷  
        //    float w = g.MeasureString(title, ft).Width; //  g.GetTextSize(ft, title).Width;
        //    float left = pageMargin;
        //    if (lcr == 1) left = (pageSize.Width - w) / 2;
        //    if (lcr == 2) left = pageSize.Width - w;
        //    g.DrawString(title, ft, brush, new PointF(left, pageMargin));
        //}
        //public static  void PrintTail(Graphics g, int index, int total)
        //{
        //    Font ft = new Font("宋体", 9f, FontStyle.Regular);
        //    Brush brush = new SolidBrush(Color.Black);//画刷  
        //    StringBuilder sb = new StringBuilder().Append("第").Append(index).Append("页 共").Append(total).Append("页");
        //    float w = g.MeasureString(sb.ToString(), ft).Width;
        //    float left = pageSize.Width - pageMargin - w;
        //    g.DrawString(sb.ToString(), ft, brush, new PointF(left, pageSize.Height - pageMargin * 0.9f));
        //}
    }
}
